package com.tencent.live.view.storage;

import android.util.Log;

import com.tencent.live.bean.upload.TokenBean;
import com.tencent.qcloud.core.auth.BasicLifecycleCredentialProvider;
import com.tencent.qcloud.core.auth.QCloudLifecycleCredentials;
import com.tencent.qcloud.core.auth.SessionQCloudCredentials;
import com.tencent.qcloud.core.common.QCloudClientException;

public class MyCredentialProvider extends BasicLifecycleCredentialProvider {

    String tmpSecretId = "";
    String tmpSecretKey = "";
    String sessionToken = "";
    long expiredTime;

    @Override
    protected QCloudLifecycleCredentials fetchNewCredentials() throws QCloudClientException {

        // 首先从您的临时密钥服务器获取包含了签名信息的响应

        // 然后解析响应，获取密钥信息
        //tmpSecretId = "AKIDbVz7b2ApfztfTj646hL2rOQjErBxysR0";   //临时密钥 secretId AKIDbVz7b2ApfztfTj646hL2rOQjErBxysR0
        //tmpSecretKey = "j8JNOBYvFVukaTQOq0ZIm1Qp5FfUE2pj"; //临时密钥 secretKey j8JNOBYvFVukaTQOq0ZIm1Qp5FfUE2pj
        //sessionToken = "440175f1f0fde7ddc94bfc68594b471047f6bdc230001";         //临时密钥 Token 440175f1f0fde7ddc94bfc68594b471047f6bdc230001


        //long expiredTime = 1556183496L;//临时密钥有效截止时间戳，单位是秒


        /*强烈建议返回服务器时间作为签名的开始时间，用来避免由于用户手机本地时间偏差过大导致的签名不正确 */
        // 返回服务器时间作为签名的起始时间
        long startTime = 1556182000L; //临时密钥有效起始时间，单位是秒

        // todo something you want

        // 最后返回临时密钥信息对象
        return new SessionQCloudCredentials(tmpSecretId, tmpSecretKey, sessionToken, startTime, expiredTime);
    }

    public void setTmpParams(TokenBean.DataBean dataBean) {

        tmpSecretId = dataBean.getCredentials().getTmpSecretId();
        tmpSecretKey = dataBean.getCredentials().getTmpSecretKey();
        sessionToken = dataBean.getCredentials().getSessionToken();
        expiredTime = dataBean.getExpiredTime();

        Log.i("yjj", "tmpSecretId =" + tmpSecretId + ", tmpSecretKey =" +
                tmpSecretKey + ", sessionToken =" + sessionToken);
    }



}